Smart Buttons
Controls/XML Elements
Loops <ForEach>
A loop is a sequence of statements that is specified once, but can be carried out several times in succession.
The code "inside" the loop (the body of the loop is everything in <Action> element) is obeyed either:
-
A specified number of times (For Loop)
-
Once for each of a collection of items (ForEach Loop)
For example, you can have a collection of phone line numbers (2;4;5), and you want to perform the same action (cancel) for each phone line.
Configuring
It is recommended to configure using the fields in the Loops XML Generator. However, you can also configure using XML.
Configuring with the Loops XML Generator
To configure with the Loops Editor:
-
Open the Smart Buttons Editor to create a script.
-
Click Loops <ForEach> to display the Loops XML Generator.
-
In Loop type, select either:
-
For Each loop
A control flow statement for traversing items in a collection. In other words, a For Each loop essentially says do this set of code for every element from the collection, rather than do this function x times.
InstructionsTo complete a For Each loop:
-
In Elements list, enter the collection of elements.
-
For static values, delimit each element with a semicolon.
Example: Apples;Bananas;Kiwi -
For variable values, enter the variable name that contains the collection. Enter the variable name in square brackets,
For example: [TicketNumbers]
-
-
In Action code, enter the XML elements to be executed for each element from a collection (Elements list). There can be one XML element or a set of multiple XML elements.
Symbol
Description
[@] Current item in the loop
For example:
<RunCommand>NP.Ticket number [@] has been voided</RunCommand>[@Key] Key part of the current item the in loop (if the source collection is 'Value/Key' collection).
[@Value] Value part of the current item in the loop (if the source collection is 'Value/Key' collection).
For example, if:
-
The Value**Key collection is: IBM**2389;VOXAT**2670000;FUJI**897;XERAB**9736888,
-
You want to display a message only with the customer name (Value part of element).
-
Enter the customer number in a DI remark (Key part of the element).
Copy<Action>
<ShowMessage>Company name is [@Value]</ShowMessage>
<RunCommand>DI.FT-Customer number: [@Key]</RunCommand>
</Action> -
-
-
For Loop
A control flow statement for traversing items specific number of times. In other words, a For loop essentially says do this set of code x times.
InstructionsTo complete a For loop, enter the following attributes.
Attribute
Description
Start number The number to start.
You can also enter a variable in square brackets. The variable value must be a number.
For example: [FirstAirSegmentNumber]
End number The number to finish.
You can also enter a variable in square brackets. The variable value must be a number.
For example: [LastAirSegmentNumber]
Step The increment number.
For example, enter 2 to iterate every second element.
You can also a enter variable in square brackets. The variable value must be a number. For example: [PaxCount]
Action code Enter that XML elements to be executed. There can be one element or a set of multiple elements.
To use the value of the current element, which is the current iteration number, use the [@] symbol for the current iteration number in the loop.
-
Click SUBMIT.
Configuring with XML
You can also enter all associated XML directly into the Smart Buttons editor.
Tip! You can add the XML code directly to the editor by dragging and dropping the blue button for this control.
ForEachLoop
A control flow statement for traversing items in a collection. In other words, a For Each loop essentially says do this set of code for every element from the collection, rather than do this function x times.
<ForEach ElementsList="">
<ElementsList>
</ElementsList>
<Action EasyMode="False">
</Action>
</ForEach>
Elements
The <ForEach> element contains two child elements: <ElementsList> and <Action>.
<ForEach> has only one attribute, ElementsList. Use @ElementsList when the collection is in a variable. ForEach @Elements list can then be used in place of the <ElementsList> element. For example:
<ForEach ElementsList="[TicketNumbers]">
<Action>
<ShowMessage>[@]</ShowMessage>
</Action>
</ForEach>
If your collection is an array of static values, use the <ElementsList> element. For example:
<ForEach>
<ElementsList> 2374678;3279,2,7
</ElementsList>
<Action EasyMode="False">
<ShowMessage>[@]</ShowMessage>
</Action>
</ForEach>
If the collection contains characters specific to XML mark-up such as tags < and >, but you want Smart Buttons to interpret these characters literally as textual data, use a CDATA structure <![CDATA[ …… ]]> to contain the text.
For example:
If a collection contains Greater Than < and Less Than > symbols:
<1>;2xn2>;3;654
Incorrect method for adding the collection:
Correct method for adding the collection:
<ForEach ElementsList="">
<ElementsList>
<![CDATA[<1>;<2>]]>
</ElementsList>
<ElementsList> can also be used for collection under Variable name for example,
<ForEach>
<ElementsList>[CustomerNumbers]</ElementsList>
<Action>
<ShowMessage>[@]</ShowMessage>
</Action>
</ForEach>
Enter the XML elements to be executed for each element from a collection (Elements list). There can be one XML element or a set of multiple XML elements.
As a value of this XML element enter any single or multiple controls that you want to be executed for each loop of <ForEach>. If some of your controls need to use the current element from the collection ten use below symbols:
Symbol |
Description |
---|---|
[@] |
Current item in the loop For example: |
[@Key] |
Key part of the current item the in loop (if the source collection is 'Value/Key' collection). |
[@Value] |
Value part of the current item in the loop (if the source collection is 'Value/Key' collection). For example, if:
Copy
|
Examples
This example:
-
Reads all unvoided tickets from a *HTI display.
-
Asks the agent which tickets to void.
-
For all selected tickets, perform the same action (voiding tickets).
<ButtonConf ButtonName="Void tickets">
<RunCommand>*HTI</RunCommand>
<GetString VarName="UnvoidedTicketNumbers"><![CDATA[(?!.*\/VOID)\/(\d{13})\/-[A- Z]{3}\/]]></GetString>
<CheckListBox Question="Select tickets you want to void" ToolTip="" Width="200" SelectDefaultAll="False" VarName="SelectedTicketsForVoid" IsRadioButton="False" SingleSelect="False" IsMandatory="False">[UnvoidedTicketNumbers]
</CheckListBox>
<ForEach>
<ElementsList>[SelectedTicketsForVoid]</ElementsList>
<Action>
<RunCommand>TRV/[@]</RunCommand>
<RunCommand>IR</RunCommand>
</Action>
</ForEach>
<RunCommand>*HTI</RunCommand>
</ButtonConf>
This example:
-
Reads all PNR numbers and PCCs from an Excel file to create a Value**Key collection.
-
Opens each PNR from the list.
-
Sends the booking to the corresponding PCC.
<ButtonConf ButtonName="Sending PNRs to Q" Description="" QuickCommand="">
<ReadFromExcel VarName="PNRNumbersAndPCCs" ExcelPath="C:\Documents\PNRs.xlsx" SheetName="PNRs1" ReadBy="Column" Column="A" Row="3:" ColumnKey="B" />
<ForEach>
<ElementsList>[PNRNumbersAndPCCs]</ElementsList>
<Action>
<RunCommand>*[@Value]</RunCommand>
<RunCommand>QEB/[@Key]/90</RunCommand>
</Action>
</ForEach>
</ButtonConf>
In this example, there are a collection of phone line numbers (2;4;5). You want to perform the same action (cancel) for each phone line element.
Inside the <ForEach> element, you need to use an <Action> child element to define the action you want to perform in each loop. You can define actions for Simple Collections as well as for Value**Key collections.
Note: [@] means the value of the current element in the loop.
<ButtonConf ButtonName="Canceling Phone Numbers" Description="" QuickCommand="">
<Variable VarName="PhoneLineNumbers">2;4;5</Variable>
<ForEach>
<ElementsList>[PhoneLineNumbers]</ElementsList>
<Action>
<RunCommand>P.[@]@</RunCommand>
</Action>
</ForEach>
</ButtonConf>
ForLoop
A control flow statement for traversing items specific number of times. In other words, a For loop essentially says do this set of code x times.
<ForEach>
<ForStatement StartNumber="" EndNumber="" Step="" />
<Action></Action>
</ForEach>
This example:
-
Counts the number of passengers in a PNR (VarName="PaxCount).
-
Asks a question about the Date of Birth (DOB) for each passenger in the PNR.
-
Adds the date of birth as a Passenger Name remark.
Create a ForLoop with a StartNumber of "1" and an EndNumber with the Numbers variable: [PaxCount].
<ButtonConf ButtonName="ForLOop" Description="" QuickCommand="">
<Variable VarName="PaxCount">%PassengersCount%</Variable>
<ForEach>
<ForStatement StartNumber="1" EndNumber="[PaxCount]" Step="1" />
<Action>
<QuestionsBlock SubmitButtonName="SUBMIT" WindowId="62f95aeb-3cb4-4004-b082-f15307006e50" Designer="True">
<TextBlock Bold="False" VarName="SBAuto_TextBlock_14eab76f-455d-4220-9d10-f311c8f1ab6b" X="10" Y="10">Enter Pax [@] DOB:</TextBlock>
<TextBox VarName="DOB" Width="100" TabIndex="0" X="140" Y="10"></TextBox>
</QuestionsBlock>
<RunCommand>N.P[@]@*DOB[DOB]</RunCommand>
</Action>
</ForEach>
</ButtonConf>
Dialog box for date of birth:
Date of birth added to PNR: